import type {Ref} from "vue";

type StateHandlers = {
    set: (newValue: boolean) => void;
    toggle: () => void;
    setTrue: () => void;
    setFalse: () => void;
};
export const useBoolean = (defaultValue: boolean = false): [Ref<boolean>, StateHandlers] => {
    const value = ref(defaultValue)
    const set = (val: boolean) => {
        value.value = val
    }
    const toggle = () => {
        set(!value.value)
    }
    const setTrue = () => {
        set(true)
    }
    const setFalse = () => {
        set(false)
    }

    return [value, {set, toggle, setTrue, setFalse}]
}